﻿Public Class KeyPegList

    Private canDrag As Boolean
    Private mouseIsDown As Boolean
    Private lastUsed As PictureBox

    Private Sub KeyPegList_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Disable()
    End Sub

    Public Function GetLastUsed() As PictureBox
        Return lastUsed
    End Function

    Public Sub Enable()
        canDrag = True
    End Sub

    Public Sub Disable()
        canDrag = False
    End Sub

    Public Sub InitializeKeyPegs()
        PictureBox1.Load("artwork\white.png")
        PictureBox2.Load("artwork\black.png")
    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        If Not PictureBox1.Image Is Nothing Then
            If canDrag Then
                mouseIsDown = True
            End If
        End If
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If mouseIsDown Then
            lastUsed = PictureBox1
            PictureBox1.DoDragDrop(PictureBox1.Image, DragDropEffects.Copy)
        End If

        mouseIsDown = False
    End Sub

    Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown
        If Not PictureBox2.Image Is Nothing Then
            If canDrag Then
                mouseIsDown = True
            End If
        End If
    End Sub

    Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
        If mouseIsDown Then
            lastUsed = PictureBox2
            PictureBox2.DoDragDrop(PictureBox2.Image, DragDropEffects.Copy)
        End If

        mouseIsDown = False
    End Sub

End Class
